import { LOGIN_PATH } from '@/utils/consts';
import { Modal } from 'antd';
import { useState } from 'react';
import { history } from 'umi';

let globalShowModal: (() => void) | null = null;

const ReLoginModal = () => {
    const [visible, setVisible] = useState(false);

    globalShowModal = () => setVisible(true);

    const handleOk = () => {
        setVisible(false);
        history.push(LOGIN_PATH);
    };

    return (
        <Modal
            title="会话过期"
            visible={visible}
            onOk={handleOk}
            onCancel={() => setVisible(false)}
            okText="重新登录"
            cancelText="稍后再说"
        >
            <p>您的登录状态已过期，请重新登录</p>
        </Modal>
    );
};
const showReLoginModal = () => {
    globalShowModal?.();
};
export { ReLoginModal, showReLoginModal };